package com.sakura.thread.chapter1.test7;

/**
 * Created by apple on 2018/12/11.
 */
public class ThreadActive {
    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("threadOne sleep for 2000 seconds");
                    Thread.sleep(2000000);
                    System.out.println("threadOne awaking");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("threadOne-leaving normally");

                //测试再次睡眠
                try {
                    System.out.println("another threadOne sleep for 20 seconds");
                    Thread.sleep(20000);
                    System.out.println("another threadOne awaking");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("another threadOne-leaving normally");

            }
        });

        threadOne.start();

        Thread.sleep(1000);

        threadOne.interrupt();

        threadOne.join();

        System.out.println("main thread is over");
    }
}
